package com.zyp.shop.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyp.shop.dao.TestDao;
import com.zyp.shop.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Intellij IDEA
 *
 * @author 赵雅璞
 * @Date: 2022/11/17 12:12
 * @Version 1.0
 */
@Service("TestService")
public class TestService {
    @Autowired
    private TestDao testDao;

    public int insertTest(){
        return testDao.insert();
    }

    public PageInfo<Student> selectAllStudents() {
        // pageNum 第几页 pageSize 一页几条
        PageHelper.startPage(2,3);
        // 查询回来的结果
        List<Student> students = testDao.selectAllStudents();
        // 将查询的结果 放入 pageInfo 中里面会有方法处理上方 29行的设置 也可以说是按照上方的设置
        // 进行分页
        PageInfo<Student> objectPageInfo = new PageInfo<>(students);
        return objectPageInfo;
    }

    public int updateStudent() {
        return testDao.updateStudent(new Student(2,"刘德华",18));
    }

    public int deleteStudent() {
        return testDao.deleteStudent(2);
    }
}
